<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <link type="text/css" rel="stylesheet" href="converter.css" />
    <head>
        <h:head>
            <title>Welcome to Currency Converter</title>
        </h:head>
    </head>
    <body>
        <h:body>
            <h1>Universal Currency Converter</h1>
            <h:form>
                <table align="center">
                    <tr>
                        <td>
                            <h:link value="login" outcome="login" rendered="#{!usrManager.loggedIn}"/>
                            <h:commandLink id="logout" action="#{usrManager.logout()}" rendered="#{usrManager.loggedIn}">
                                <h:outputText value="logout"/>
                            </h:commandLink>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputText id="userName" value="#{usrManager.fullName}" rendered ="#{usrManager.loggedIn}"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:commandLink id="adminPage" action="adminPage" rendered="#{usrManager.role == 1}">
                                <h:outputText value="go to adminPage"/>
                            </h:commandLink>
                        </td>
                    </tr>
                </table>
                <p align="center">
                    <c:choose>
                        <c:when test="#{converterManager.exception.cause != null}">
                            <h3><h:outputText value="#{converterManager.exception.cause.message}"/></h3>
                        </c:when>
                        <c:otherwise>
                            <h3><h:outputText value="#{converterManager.exception.message}"/></h3>
                        </c:otherwise>
                    </c:choose>
                </p>
                <table align="center" width="30%">
                    <tr>
                        <td>
                            <h:outputLabel for="srcCurDrpDown" value="From:" />
                        </td>
                        <td>
                            <h:selectOneMenu id="srcCurDrpDown" value="#{converterManager.srcCurrency}" >
                                <f:selectItems value="#{converterManager.currencyList}" />
                            </h:selectOneMenu> 
                            <br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputLabel for="dstCurDrpDown" value="To:" />
                        </td>
                        <td>
                            <h:selectOneMenu id="dstCurDrpDown" value="#{converterManager.dstCurrency}" >
                                <f:selectItems value="#{converterManager.currencyList}" />
                            </h:selectOneMenu> 
                            <br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputLabel for="amount" value="Amount:"/>
                        </td>
                        <td>
                            <h:inputText id="amount" value="#{converterManager.amount}" validator="#{converterManager.validateAmount}"/>
                            <h:message for="amount" showSummary="#{true}" showDetail="#{false}"/>
                            <br/>
                        </td>
                    </tr>
                    <br/>
                    <br/>
                    <tr>
                        <td></td>
                        <td>
                            <h:commandButton value="Convert" action="#{converterManager.convert()}" />
                            <br/>
                            <br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputLabel for="convertValue" value="Value:"/>
                        </td>
                        <td>
                            <h:outputText id="convertValue" value="#{converterManager.value}" />
                        </td>
                    </tr>
                </table>
            </h:form>
        </h:body>
    </body>
</html>